package com.insurance.service.impl;

import com.insurance.mapper.UserMapper;
import com.insurance.pojo.*;
import com.insurance.service.UserService;
import com.insurance.utils.ConversionDateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: yjc
 * Date: 2020/10/27 11:29
 * Description:
 * Version: V1.0
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public List<Map> queryUser(User user) {
        List<Map> list=userMapper.queryUser(user);
        System.out.println(list);
        for (Map map:list){
            if (map.get("user_last_time") != null){
                String date=ConversionDateUtils.conversionDateStringUtils(map.get("user_last_time"));
                map.put("user_last_time",date);
            }
        }
        return list;
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public List<Map> queryOwnerCard(OwnerCard ownerCard) {
        List<Map> list=userMapper.queryOwnerCard(ownerCard);
        for (Map map:list){
            if(map.get("owner_first_date") != null){
                String date=ConversionDateUtils.conversionDateStringUtils(map.get("owner_first_date"));
                map.put("owner_first_date",date);
            }
        }
        return list;
    }

    @Override
    public int addOwnerCard(OwnerCard ownerCard) {
//        userMapper.addOwnerCard(ownerCard);
        //把添加的行驶证id返回
        userMapper.addOwnerCardToVL(ownerCard);
        int vehicle_license_id = ownerCard.getVehicleLicenseId();
        //把添加的车辆id返回
        userMapper.addOwnerCardToC(ownerCard);
        int car_id = ownerCard.getCar_id();
        userMapper.addOwnerCardToU(ownerCard);
        return userMapper.addOwnerCard(ownerCard);
    }

    @Override
    public int updateOwnerCard(OwnerCard ownerCard) {
        userMapper.updateOwnerCardToVL(ownerCard);
        userMapper.updateOwnerCardToC(ownerCard);
        userMapper.updateOwnerCardToU(ownerCard);
        return userMapper.updateOwnerCard(ownerCard);
    }

    @Override
    public List<Map> queryDriver(Driver driver) {
        List<Map> list=userMapper.queryDriver(driver);
        for (Map map:list){
            if (map.get("user_last_time") != null){
                String date=ConversionDateUtils.conversionDateStringUtils(map.get("user_last_time"));
                map.put("user_last_time",date);
            }
        }
        return list;
    }

    @Override
    public int addDriver(Driver driver) {
        userMapper.addDriverToU(driver);
        return userMapper.addDriver(driver);
    }

    @Override
    public List<Map> queryBrand(Brand brand) {
        return userMapper.queryBrand(brand);
    }

    @Override
    public List<Map> queryCarModel(CarModel carModel) {
        return userMapper.queryCarModel(carModel);
    }

    @Override
    public List<Map> queryCarSpecificModels(CarSpecificModels carSpecificModels) {
        return userMapper.queryCarSpecificModels(carSpecificModels);
    }

    @Override
    public int updateDriver(Driver driver) {
        userMapper.updateDriverToU(driver);
        return userMapper.updateDriver(driver);
    }

    @Override
    public int delDriver(Driver driver) {
        userMapper.delDriverToU(driver);
        return userMapper.delDriver(driver);
    }
}
